package com.ice.chatserver.service.impl;

import com.ice.chatserver.dao.UserSettingDao;
import com.ice.chatserver.pojo.UserSetting;
import com.ice.chatserver.service.UserSettingService;
import lombok.extern.slf4j.Slf4j;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
* @author ice2020x
* @Date: 2023/2/3
* @Description: 用户设置
**/
@Service
@Slf4j
public class UserSettingServiceImpl implements UserSettingService {

    @Resource
    private UserSettingDao userSettingDao;

    @Resource
    private MongoTemplate mongoTemplate;


    @Override
    public UserSetting findByUserId(String userId) {
        Query query = new Query();
        query.addCriteria(Criteria.where("userId").is(userId));
        UserSetting userSetting = mongoTemplate.findOne(query, UserSetting.class);
        log.info("用户{}的用户设置信息为：{}",userId,userSetting);
        return userSetting;
    }

    @Override
    public UserSetting save(UserSetting setting) {
        return userSettingDao.save(setting);
    }

    @Override
    public UserSetting update(UserSetting userSetting) {
        return userSettingDao.save(userSetting);
    }


}
